﻿using B.S.Outsourcing.ErrorCode;
using B.S.Outsourcing.Writer.Api.Application.Command;
using B.S.Outsourcing.Writer.Api.Application.Command.OutsourcingArrivalOrderModel;
using B.S.Outsourcing.Writer.Api.Application.Command.OutsourcingMaterialReleaseOrderModel;
using B.S.Outsourcing.Writer.Api.Application.Command.OutSourOrderModel;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Outsourcing.Writer.Api.Controllers
{
    /// <summary>
    /// 委外——写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OutsourController : ControllerBase
    {
        private readonly IMediator mediator;
        //private readonly ILogger<OutsourController> logger;

        public OutsourController(IMediator mediator)
        {
            this.mediator = mediator;
            //ILogger<OutsourController> logger = null
            //this.logger = logger;
        }
        /// <summary>
        /// 添加委外生产商
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddOutSour(CreateOutsourcingCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 删除委外生产商
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteOutSour(DeleteOutSourcCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 修改生产商
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateOUtsourc(UpdateOutsourCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 批量删除生产商
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteAll([FromBody]DeleteOutSourGetAllCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 添加委外订单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddOutSourOrder(CreateOutSourOrderCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除委外订单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteOutSourOrdere(DeleteOutSourOrderCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 修改委外订单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateOutSourOrder(UpdateOutSourOrderCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 批量删除委外订单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteGetAllOrderID(DeleteOutsourOrderGetAllCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 添加委外到货单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddoutSourArrival(CreateOutsourcingArrivalCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 批量删除委外到货单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteOutArrval(DeleteOutSoutArrivalAllCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除委外到货单 单条数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteOutArrvalID(DeleteOutSoutArrivalIDCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 修改委外到货单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateOutArrval(UpdateOutSourcingArrivalCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 添加发料单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddOutsourMateria(CreateOutsourcingMaterialReleaseCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 删除发料单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteOutsourMateria(DeleteOutSourReleaseOrderCommand request)
        {
            try
            {
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                //logger.LogError("添加委外生产商时出现异常:"+ex.Message);
                throw;
            }
        }
    }
}
